#include "src/misc.h"

void generateRandomPolygon(int n, cv::RNG& rng, TGPolygon& polygon) {
    polygon.init();
    polygon.data.reserve(n);
    for(int i = 0; i < n; i ++) {
        polygon.data.emplace_back(rng.uniform(0, 10)*100, rng.uniform(0, 10)*100);
    }
    antiClockwiseAndRemoveDuplicate(polygon);
}

//随机生成含有n点的集合
void generateRandomPointSet(int n, cv::RNG& rng, std::vector<TGPoint>& dst) {
    dst.clear();
    dst.reserve(n);
    for(int i = 0; i < n; i ++) {
        dst.emplace_back(rng.uniform(30,240), rng.uniform(40,320));
    }
}

void drawPolygon(cv::Mat& img, TGPolygon& polygon, const cv::Scalar& color, bool fill) {
    std::vector<cv::Point>pts;
    pts.reserve(polygon.data.size());
    for(const auto& p : polygon.data) {
        pts.emplace_back(int(p.x), int(p.y));
    }
    if(!fill)
        polylines(img, pts, true, color, 1);
    else{
        fillPoly(img, pts, color);
    }
    cv::imshow("Main", img);
}

void drawPoints(cv::Mat& img, const cv::Scalar& color, std::vector<TGPoint>& points) {
    int n = points.size();
    for(int i = 0; i < n; i ++) {
        cv::circle(img, {int(points[i].x), int(points[i].y)}, 3, color, 1);
    }
    cv::imshow("Main", img);
}